/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#ifndef LIB3D_MATH_H
#define LIB3D_MATH_H

#include <math/Vector3.h>
#include <math/Matrix4.h>
#include <math/Sphere.h>

namespace liba
{
namespace lib3d
{

typedef math::Vector<float,2> UV;
typedef math::Vector3<float> Vector;
typedef math::Vector<float,4> Plane;
typedef math::Matrix4<float> Matrix;
typedef math::Sphere Sphere;

class Viewport
{
public:
	double left, right, top, bottom;

	Viewport()
	:	left( 0 ),
		right( 1 ),
		top( 0 ),
		bottom( 1 )
	{}
	Viewport( double left, double right, double top, double bottom )
	:	left( left ),
		right( right ),
		top( top ),
		bottom( bottom )
	{}
};

class Ray
{
public:
	Ray()
	{}
	Ray(const Vector & pos, const Vector & dir ):
		pos(pos),
		dir(dir)
	{
//		this->dir.normalize();
	}
	const lib3d::Vector & get_position()const
	{
		return pos;
	}
	const lib3d::Vector & get_direction()const 
	{
		return dir;
	}
private:
	Vector pos;
	Vector dir; 
};

Matrix calculate_perspective_projection_matrix( double fov, double aspect, double near_plane, double far_plane );
Matrix calculate_orthogonal_projection_matrix( double left, double right, double bottom, double top, double near_plane, double far_plane );


Vector clamp( const Vector & value, const Vector & mi, const Vector & ma );

} // namespace lib3d
} // namespace liba
using namespace liba;

#endif //LIB3D_MATH_H